﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://www.resamu.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ResaFdxml
    Inherits System.Web.Services.WebService

    <WebMethod()> _
   Public Function Test(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String) As String
        Dim message As String
        Dim securite As New ResaSecurite.user
        securite.Url = Application("ResaSecurite")
        securite.Timeout = 60000
        Dim log As New ResaSurvey.logsurvey
        log.Url = Application("ResaSurvey")
        log.Timeout = 60000
        Try
            message = securite.Identification(idresamu, pwd, idpers)
        Catch ex As Exception
            message = ex.Message
        End Try
        Try
            log.NewLog(idresamu, "system", idpers, "TESTFDXML", message)
        Catch ex As Exception

        End Try
        Return message
    End Function
    <WebMethod()> _
    Public Function NewTeam(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String, ByVal COMREF As String, ByVal fdxml As System.Xml.XmlDocument) As String
        Dim message As String
        Dim xmlnode As System.Xml.XmlNode
        Dim personnes As System.Xml.XmlNodeList

        Dim securite As New ResaSecurite.user
        securite.Url = Application("ResaSecurite")
        securite.Timeout = 60000

        Dim log As New ResaSurvey.logsurvey
        log.Url = Application("ResaSurvey")
        log.Timeout = 60000
        Try
            Dim analyse As String()
            analyse = securite.Identification(idresamu, pwd, idpers).Split("/")
            If analyse(0) = "IDOK" Then
                Dim dbTeam As New DataSetTeamTableAdapters.LIST_EQUIPETableAdapter
                Dim dbPers As New DataSetPersTableAdapters.liste_persTableAdapter
                dbTeam.Insert(fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("idteam").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("idresamu").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("type").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("etat").SelectSingleNode("dispo").InnerText, Now(), _
                fdxml.DocumentElement.SelectSingleNode("etat").SelectSingleNode("utmx").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("etat").SelectSingleNode("utmy").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("veh").SelectSingleNode("tel").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("veh").SelectSingleNode("radio").InnerText, _
                fdxml.DocumentElement.SelectSingleNode("veh").SelectSingleNode("type").InnerText, "", _
                analyse(5), COMREF, fdxml)
                '<On ajoute les personnes à la liste des personnes>
                personnes = fdxml.DocumentElement.SelectNodes("pers")
                For Each xmlnode In personnes
                    dbPers.Insert(xmlnode.SelectSingleNode("nom").InnerText, _
                    xmlnode.SelectSingleNode("prenom").InnerText, xmlnode.SelectSingleNode("fct").InnerText, _
                    fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("idteam").InnerText, _
                    fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("idresamu").InnerText, _
                    xmlnode.SelectSingleNode("prenom").InnerText + " " + xmlnode.SelectSingleNode("nom").InnerText)
                Next
                message = "NEWTEAMOK"
            Else
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            message = "ERROR/" = ex.Message
        End Try
        Try
            log.NewLog(idresamu, fdxml.DocumentElement.SelectSingleNode("id").SelectSingleNode("idteam").InnerText, _
            idpers, "NewTeam", message)
        Catch ex As Exception

        End Try
        Return message
    End Function
    <WebMethod()> _
    Public Function GetFdxmlStructure(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String) As System.Xml.XmlDocument
        Dim doc As New System.Xml.XmlDocument
        Dim message As String
        Dim securite As New ResaSecurite.user
        securite.Url = Application("ResaSecurite")
        securite.Timeout = 60000
        Dim log As New ResaSurvey.logsurvey
        log.Url = Application("ResaSurvey")
        log.Timeout = 60000

        Try
            Dim analyse As String()
            analyse = securite.Identification(idresamu, pwd, idpers).Split("/")
            If analyse(0) = "IDOK" Then
                doc.Load(Server.MapPath("") + "/FDXML.xml")
                message = "GetStructureOK"
            Else
                doc.LoadXml("<ERROR>INTRUSION</ERROR>")
                message = "INTRUSION"
            End If
        Catch ex As Exception
            doc.LoadXml("<ERROR>" + ex.Message + "</ERROR>")
            message = ex.Message
        End Try
        log.NewLog(idresamu, "system", idpers, "GetFdxmlStructure", message)
        Return doc
    End Function
    <WebMethod()> _
    Public Function GetPersInfo(ByVal servercode As String, ByVal idresamu As String, ByVal idpers As String) As String
        Dim log As New ResaSurvey.logsurvey
        log.Url = Application("ResaSurvey")
        log.Timeout = 60000
        Dim message As String
        If servercode = "Res@Core16" Then
            Try
                Dim PersData As New DataSetPersTableAdapters.liste_persTableAdapter
                Dim dbPers As New DataSetPers.liste_persDataTable
                dbPers = PersData.GetDataByIdPersIdResamu(idpers, idresamu)
                If dbPers.Rows.Count = 0 Then
                    message = "NOPERS"
                Else
                    message = "PERSOK/" + dbPers(0).idteam + "/" + dbPers(0).fct
                End If
            Catch ex As Exception
                message = "ERROR/" + ex.Message
            End Try
        Else
            message = "ERROR/INTRUSION"
        End If
        Try
            log.NewLog(idresamu, "system", idpers, "GETPERSINFO", message)
        Catch ex As Exception

        End Try
        Return message
    End Function
    <WebMethod()> _
    Public Function GetTeamByIdResamu(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String) As System.Xml.XmlDocument
        Dim message As String
        Dim analyse As String()
        Dim listequipe As New System.Xml.XmlDocument
        '-------------------------------------------
        Dim securite As New ResaSecurite.user
        securite.Url = Application("ResaSecurite")
        securite.Timeout = 60000
        '-------------------------------------------
        Dim log As New ResaSurvey.logsurvey
        log.Url = Application("ResaSurvey") 'todo mettre en place autre gestion
        log.Timeout = 60000
        '-------------------------------------------
        Dim TeamData As New DataSetTeamTableAdapters.LIST_EQUIPETableAdapter
        Dim dbTeam As New DataSetTeam.LIST_EQUIPEDataTable
        '-------------------------------------------
        Try
            message = securite.Identification(idresamu, pwd, idpers)
            analyse = message.Split("/")
            If analyse(0) = "IDOK" Then
                dbTeam = TeamData.GetDataByIdResamu(idresamu)
                dbTeam.WriteXml(Server.MapPath("") + "/XMLWORK/" + idresamu + "listequipe.xml")
                listequipe.Load(Server.MapPath("") + "/XMLWORK/" + idresamu + "listequipe.xml")
                message = "GetTeamByIdResamuOK"
            Else
                listequipe.LoadXml("<FDXML><ERROR>INTRUSION</ERROR></FDXML>")
            End If
        Catch ex As Exception
            listequipe.LoadXml("<FDXML><ERROR>" + ex.Message + "</ERROR></FDXML>")
            message = ex.Message
        End Try
        Try
            log.NewLog(idresamu, "system", "system", "GetTeamByIdResamu", message)
        Catch ex As Exception
        End Try
        Return listequipe
    End Function

End Class
